﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using ZR.Admin.WebApi.Extensions;
using ZR.Model.mes.md;
using ZR.Model.System.Dto;
using ZR.Service.mes.md;
using ZR.Service.mes.md.IService;

namespace ZR.Admin.WebApi.Controllers.mes.md
{
    [Route("mes/md/workshop")]
    public class MdWorkshopController : BaseController
    {
        IMdWorkshopService mdWorkshopService;

        public MdWorkshopController(IMdWorkshopService mdWorkshopService)
        {
            this.mdWorkshopService = mdWorkshopService;
        }
        /// <summary>
        /// 获取车间列表信息
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <param name="workshopId"></param>
        /// <param name="workshopName"></param>
        /// <param name="workshopPosition"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public IActionResult List(int pageNum, int pageSize, string workshopId = "", string workshopName = "", string workshopPosition = "")
        {

            (int, List<MdWorkshop>) data = mdWorkshopService.GetAll(workshopId, workshopName, workshopPosition, pageNum, pageSize);

            return ToResponse(new ApiResult(200, "success", data));

        }
        /// <summary>
        /// 插入车间
        /// </summary>
        /// <param name="workshop"></param>
        /// <returns></returns>
        [HttpPost("addWorkshop")]
        public IActionResult AddWorkshop([FromBody] MdWorkshop workshop)
        {
            if (workshop == null)
            {
                return ToResponse(new ApiResult((int)ResultCode.NO_DATA, "null"));
            }
            if (workshop != null)
                workshop.ToCreate(HttpContext);
            int result = mdWorkshopService.AddWorkshop(workshop);
            return SUCCESS(result);
        }


        [HttpPost("updateWorkshop")]
        public IActionResult UpdateWorkshop([FromBody] MdWorkshop workshop)
        {
            if(workshop!=null)  
                workshop.ToUpdate(HttpContext);
            int result = mdWorkshopService.UpdateWorkshop(workshop);
            return SUCCESS(result);
        }


        [HttpPost("delWorkshop")]
        public IActionResult deleteWorkshop([FromBody] List<int> ids)
        {
            if (ids != null)
            {
                int result = mdWorkshopService.deleteWorkshop(ids.ToArray());
                return ToResponse(result);
            }
            return null;            
        }




    }
}
